// FILEPATH: src/modules/game-rule/game-rule.service.ts

import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CreateGameRuleDto } from './dto/create-game-rule.dto';
import { UpdateGameRuleDto } from './dto/update-game-rule.dto';
import { GameRule } from './entities/game-rule.entity';

@Injectable()
export class GameRuleService {
  constructor(
    @InjectRepository(GameRule)
    private gameRuleRepository: Repository<GameRule>,
  ) {}

  async create(createGameRuleDto: CreateGameRuleDto): Promise<GameRule> {
    const gameRule = this.gameRuleRepository.create(createGameRuleDto);
    return await this.gameRuleRepository.save(gameRule);
  }

  async findAll(): Promise<GameRule[]> {
    return await this.gameRuleRepository.find();
  }

  async findOne(id: number): Promise<GameRule> {
    return await this.gameRuleRepository.findOne({ where: { id } });
  }

  async update(
    id: number,
    updateGameRuleDto: UpdateGameRuleDto,
  ): Promise<GameRule> {
    await this.gameRuleRepository.update(id, updateGameRuleDto);
    return this.findOne(id);
  }

  async remove(id: number): Promise<void> {
    await this.gameRuleRepository.delete(id);
  }
}
